import { Sky } from 'three/examples/jsm/objects/Sky';
import { Vector3, MathUtils } from 'three';
let sky = null;
let sun = null;
export const useSky = (scene, camera, renderer) => {
  sky = new Sky()
  sky.scale.setScalar(450000)
  sun = new Vector3(1.2239007774061617e-16, 0.03489949670250108, -0.9993908270190958)
  // 天空配置
  const effectController = {
    turbidity: 10,  // 浑浊度
    rayleigh: 5,  // 极光强度,发光强度
    mieCoefficient: 0.005,  // 系数
    mieDirectionalG: 0.7, // 定向
    elevation: 1, // 海拔仰角
    azimuth: 180, // 方位\方位角
    exposure: renderer.toneMappingExposure  // 曝光
  }
  const uniforms = sky.material.uniforms;
  uniforms['turbidity'].value = effectController.turbidity;
  uniforms['rayleigh'].value = effectController.rayleigh;
  uniforms['mieCoefficient'].value = effectController.mieCoefficient;
  uniforms['mieDirectionalG'].value = effectController.mieDirectionalG;
  const phi = MathUtils.degToRad(90 - effectController.elevation);
  const theta = MathUtils.degToRad(effectController.azimuth);
  sun.setFromSphericalCoords(1, phi, theta);
  console.log(sun, 'sun')
  uniforms['sunPosition'].value.copy(sun);
  renderer.toneMappingExposure = effectController.exposure;
  renderer.render(scene, camera);
  return sky;
}